import { Component, OnInit, Output, Input, EventEmitter, ViewChild } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-prc',
  templateUrl: './prc.component.html',
  styleUrls: ['./prc.component.scss']
})
export class PrcComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService, public request: RequestService) {

  }
  field1 = []     //table表格1-主表列字段集合
  data1 = {}      //table表格1-主表对象数据集合
  data1_dis = {}  //table表格1-主表对象禁用集合
  data1_sel = []  //table表格1-主表下拉框数据集合
  data1_selValue={} //table表格1-主表下拉框默认赋值集合
  data1_att = []  //table表格1-主表自定义属性数据集合

  @Output() private outer = new EventEmitter();
  @Input() puc_msg: any;
  /**
   * 表格字段动态列集合生成
   */
  filed_tablelist() {
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype", { "type": "purchase.PrcVo" }).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.field1=this.utilService.filed_list4(data.object);
        this.data1_selValue = this.utilService.selectDefaultValue(data.object); 
        this.popup01_table();//初始化列表表格数据
        for(var i=0;i<data.object.length;i++){
          this.data1[data.object[i]["fieldValue"]]=""
          this.data1_dis[data.object[i]["fieldValue"]]=true
        }
      }
    }
    });
  }
  unitStatus_list = JSON.parse(localStorage.getItem("unitStatus_list"))	//组织状态
  prsnlCode_lsit = JSON.parse(localStorage.getItem("userStatus_list"))	//人员状态
  userStatus_list = JSON.parse(localStorage.getItem("userStatus_list"))	//人员状态
  prodStatus_list = JSON.parse(localStorage.getItem("prodStatus_list"))	//商品状态
  prcType_list;
  srcType_list;
  acReqd_list;
  afReqd_list;
  prcSite_list;
  isCms_list;
  drDiffJgd_list;
  rtnaInvd_list;
  multiImpl_list;
  accEnabled_list;
  rtnAccSite_list;
  splEnabled_list;
  vdrInvd_list;
  vdeInvd_list;
  prBrdgMode_list;
  srBrdgMode_list;
  isPrItmd_list;
  isSrItmd_list;
  bxiEnabled_list;
  srcAutoGen_list;
  srcAutoChk_list;
  prcAutoGen_list;
  prcAutoChk_list;
  pscReqd_list;
  rtnType_list;
  delivMthd_list;
  srcGen_list;
  prcGen_list;
  acBnd_list;
  srFwdd_list;
  effective_list;
  suspended_list;
  cancelled_list;
  progress_list;
  srcDocType_list

  ngOnInit() {
    this.filed_tablelist()
    setTimeout(()=>{ 
      this.interfaceService.postPage("/erp/purchase/prc/option", {}).subscribe((data0: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data0)) {
        if (data0.code == 200) {
          var sele = data0.object;
          /* this.prcType_list = sele.prcType;
          this.srcType_list = sele.srcType;
          this.acReqd_list = sele.acReqd;
          this.afReqd_list = sele.afReqd;
          this.prcSite_list = sele.prcSite;
          this.isCms_list = sele.isCms;
          this.drDiffJgd_list = sele.drDiffJgd;
          this.rtnaInvd_list = sele.rtnaInvd;
          this.multiImpl_list = sele.multiImpl;
          this.accEnabled_list = sele.accEnabled;
          this.rtnAccSite_list = sele.rtnAccSite;
          this.splEnabled_list = sele.splEnabled;
          this.vdrInvd_list = sele.vdrInvd;
          this.vdeInvd_list = sele.vdeInvd;
          this.prBrdgMode_list = sele.prBrdgMode;
          this.srBrdgMode_list = sele.srBrdgMode;
          this.isPrItmd_list = sele.isPrItmd;
          this.isSrItmd_list = sele.isSrItmd;
          this.bxiEnabled_list = sele.bxiEnabled;
          this.srcAutoGen_list = sele.srcAutoGen;
          this.srcAutoChk_list = sele.srcAutoChk;
          this.prcAutoGen_list = sele.prcAutoGen;
          this.prcAutoChk_list = sele.prcAutoChk;
          this.pscReqd_list = sele.pscReqd;
          this.rtnType_list = sele.rtnType;
          this.delivMthd_list = sele.delivMthd;
          this.srcGen_list = sele.srcGen;
          this.prcGen_list = sele.prcGen;
          this.acBnd_list = sele.acBnd;
          this.srFwdd_list = sele.srFwdd;
          this.prodStatus_list = sele.prodStatus;
          this.effective_list = sele.effective;
          this.suspended_list = sele.suspended;
          this.cancelled_list = sele.cancelled;
          this.srcDocType_list = sele.srcDoctype; */
          this.progress_list = sele.progress;
        }
      }
      });
    },500);
  }

  popup01_url = '';
  popup01_switchUnitId = '';
  popup01 = false;
  popup01_show(url, switchUnitId): void {
    this.popup01_url = url
    this.popup01_switchUnitId = switchUnitId;
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url = '';
    this.popup01_ss1 = '';
    this.popup01_ss2 = '';
    this.popup01_ss3 = '';
    this.popup01_ss4 = '';
    this.popup01_ss5 = '';
    this.popup01_ss6 = '';
    this.popup01_ss7 = null;
  }

  venderIdss = '';
  popup01_ss1 = '';
  popup01_ss2 = '';
  popup01_ss3 = '';
  popup01_ss4 = '';
  popup01_ss5 = '';
  popup01_ss6 = '';
  popup01_ss7 = null;
  popup01_table() {
    var jindu = this.popup01_ss7
    if (this.popup01_ss7 == null) {
      jindu = ""
    } else {
      jindu = this.popup01_ss7
    }
    this.popup01_listTable(this.popup01_url + "?1=1&prcNum=" + this.popup01_ss1 + "&startTime=" + this.popup01_ss2 + "&endTime=" + this.popup01_ss3 + "&venderNum=" + this.popup01_ss4 + "&vdrWarehNum=" + this.popup01_ss5 + "&vdeWarehNum=" + this.popup01_ss6 + "&progress=" + jindu + "&switchUnitId=" + this.popup01_switchUnitId);
  }
  indexTableId = 'popup01_tblist_prc'
  popup01_listTable(url): void {
    setTimeout(() => {
      layui.use(['table',  'laydate'], (obj) => {
        var  table = layui.table,  laydate = layui.laydate;
        laydate.render({
          elem: '#popup011_ss2'
          , done: (value) => {
            this.popup01_ss2 = value;
          }
        });
        laydate.render({
          elem: '#popup011_ss3'
          , done: (value) => {
            this.popup01_ss3 = value;
          }
        });
        var tab = this.utilService.getTable(url, "#" + this.indexTableId, this.field1)
        tab["title"] = '退购弹窗数据表'
        tab["defaultToolbar"] = []
        table.render(tab);
        table.on('rowDouble(popup01_tblist_prc)', (obj) => {
          this.popup01_hide();
          this.outer.emit(obj.data)
        });

      });

    }, 50);

  }



  @ViewChild('unitsChild') units: any; //组织
  popup0_id = 0
  popup0_url = ""
  popup0_show(id, type): void {
    this.popup0_id = id
    this.popup0_url = "&unitType=" + type + "&switchUnitId=" + this.popup01_switchUnitId
    if (this.popup0_id == 1) {
      this.popup0_url = "&switchUnitId=" + this.popup01_switchUnitId
    } else if (this.popup0_id == 2) {
      this.popup0_url = "&switchUnitId=" + this.popup01_switchUnitId
    } else if (this.popup0_id == 3) {
      this.popup0_url = "&switchUnitId=" + this.popup01_switchUnitId
    }
    this.units.popup01_show("/erp/unit/option/unitOption?unitType=" + type + this.popup0_url);
  }

  unitsParent(e) {		//接收子组件传递过来的数据
    if (this.popup0_id == 1) {
      this.popup01_ss4 = e.unitCode;
    } else if (this.popup0_id == 2) {
      this.popup01_ss5 = e.unitCode;
    } else if (this.popup0_id == 3) {
      this.popup01_ss6 = e.unitCode;
    }
  }



}
